/**
 * 
 */
package com.core.web.actions;

import java.util.List;

import org.apache.struts2.components.Property;
import org.hibernate.Session;

import com.core.dao.Properties;
import com.core.utility.HibernateUtils;
import com.core.utility.Types.TransactionType;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @author e3005468
 *
 */
public class PropertiesAction extends ActionSupport implements ModelDriven<PropertiesFormBean>{
	
	 private static final long serialVersionUID = -2613425890762568273L;
	 PropertiesFormBean propBean=new PropertiesFormBean();
	public String add()
	
	
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 session.saveOrUpdate(this.getPropertiesEntity());
		 session.getTransaction().commit();
		System.out.println("addmethod----------"+propBean.bathrooms);
		propBean=null;
		return "addProperties";
	}
	public String getAllProperties()
	{
		
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List lst = session.createSQLQuery("select * from PropertyView").list();
		 System.out.println(lst.size());
		 session.getTransaction().commit();
		return null;
	}
	
	public String inputForm()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List lst = session.createSQLQuery("select propertyId from PROPERTYVIEW").list();
		 System.out.println(lst.size());
		 session.getTransaction().commit();
		return "inputFormProperties";
	}
	@Override
	public PropertiesFormBean getModel() {
		// TODO Auto-generated method stub
		System.out.println("called");
		return propBean;
	}

	public PropertiesFormBean getPropBean() {
		return propBean;
	}

	public void setPropBean(PropertiesFormBean propBean) {
		this.propBean = propBean;
	}
	
	private Properties getPropertiesEntity()
	{
		
		Properties propEntity=new Properties();
		propEntity.setAirport(propBean.getAirport());
		
		propEntity.setPropertyImage(propBean.getPropertyImage());
		propEntity.setAvailableFromMonth(Integer.parseInt(propBean.getAvailableFromMonth()));
		propEntity.setNearByDetails(propBean.getNearByDetails());
		propEntity.setPropertyAddress(propBean.getPropertyAddress());
		propEntity.setBathrooms(Integer.parseInt(propBean.getBathrooms()));
		propEntity.setUnitPrice(propBean.getUnitPrice());
		propEntity.setCityCenter(propBean.getCityCenter());
		propEntity.setCity(Integer.parseInt(propBean.getCity()));
		propEntity.setAirport( propBean.getAirport());
		propEntity.setSchools(propBean.getSchools());
		propEntity.setConstructionAge(Integer.parseInt(propBean.getConstructionAge()));
		propEntity.setTotalFloor(propBean.getTotalFloor());
		propEntity.setAvailableUnit(propBean.getAvailableUnit());
		propEntity.setPorpertyType(Integer.parseInt(propBean.getPorpertyType()));
		propEntity.setAvailableFromYear(propBean.getAvailableFromYear());
		propEntity.setTotalPrice(propBean.getTotalPrice());
		propEntity.setRailwayStation(propBean.getRailwayStation());
		propEntity.setPlotAreaIn(Integer.parseInt(propBean.getPlotAreaIn()));
		propEntity.setMetro(propBean.getMetro());
		propEntity.setPlotArea(propBean.getPlotArea());
		propEntity.setShortDesc(propBean.getShortDesc());
		//propEntity.setBedrooms(Integer.parseInt(propBean.getBedrooms()));
		propEntity.setDetailDesc(propBean.getDetailDesc());
		propEntity.setHospitals(propBean.getHospitals());
		propEntity.setTransactionType(Integer.parseInt(propBean.getTransactionType()));
		propEntity.setFurnished(Integer.parseInt(propBean.getFurnished()));
		propEntity.setFloorNo(propBean.getFloorNo());
		propEntity.setCoveredAreaIn(Integer.parseInt(propBean.getCoveredAreaIn()));
		propEntity.setPriceRange(Integer.parseInt(propBean.getPriceRange()));
		propEntity.setOwnership(Integer.parseInt(propBean.getOwnership()));
		propEntity.setUnitPriceIn(Integer.parseInt(propBean.getUnitPriceIn()));
		propEntity.setTotalPriceIn(Integer.parseInt(propBean.getTotalPriceIn()));
		propEntity.setCoveredArea(propBean.getCoveredArea());
		propEntity.setLocality(Integer.parseInt(propBean.getLocality()));
		return propEntity;
	}

}
